let id = ''
Page({
  data: {
    DataList: [],
    searchList: [],
    inputText: '',
    sumNum:'',
    isFocus: false,
    isSearch: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData()
  },

  // 输入单词
  findHistory(e) {
    if (e.detail.value.length > 0) {
      this.setData({
        isSearch: true
      })
    } else {
      this.setData({
        isSearch: false
      })
    }

    let temp = []
    let p = e.detail.value
    if (p) {
      try {
        let value = wx.getStorageSync('audioCnt')
        if (value) {
          value.forEach((item, index) => {
            if (item.indexOf(p) > -1) {
              temp.unshift(item)
            }
          })
        }
      } catch (e) {
        console.log(e)
      }
    } 
    this.setData({
      searchList: temp
    })
  },

  /**
   * 清空搜索框
   */
  clearInput(e) {
    this.setData({
      inputText: '',
      isSearch: false
    })
    this.clearList()
  },
  /**
   * 清空列表
   */
  clearList() {
    this.setData({
      searchList: []
    })
  },

  async getData() {
    let {
      result
    } = await wx.cloud.callFunction({
      name: 'getAudioCountList'
    })
    this.setData({
      DataList: result,
    })
  },

  /**
   * 单词详情
   */
  transfer(e) {
    id = e.currentTarget.dataset.val;
    let con = e.currentTarget.dataset.con 
    console.log(id, e)
    wx.navigateTo({ // 暂定为跳转提示页面
      url: '/pages/dictionary/wordDetail/wordDetail?content=' + con + '&id=' + id,
    })
  },

})